using PP.Basic;
using PP.PPPoker.Game.GJ25;
using System;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace PP.PPPoker
{
    /// <summary>
    /// GJStartLayer 对象
    /// </summary>
    public class GJStartLayer : MonoBehaviour
    {
        private const string Tag = nameof(GJStartLayer);
        
        // Private Variables Begin
        // Private Variables End
        
        // Static Methods Begin
        public static GJStartLayer Create()
        {
            return UIManager.Instance.ShowView<GJStartLayer>("Prefab/GJStartLayer");
        }
        // Static Methods End
        
        // Public Methods Begin
        // Public Methods End
        
        // Lifecycle Methods Begin
        protected void Awake()
        {
            Debug.Log($"{Tag}.Awake");
            InitHier();
            InitPart();
        }

        private void InitPart()
        {
            // Do initialization here...
        }
        
        private void Start()
        {
            Debug.Log($"{Tag}.Start");
        }
        
        // Lifecycle Methods End

        // Hier Components Begin        
        private Button _startButton;
        private Button _ruleButton;
        private TMP_InputField _inputField;
        private GJToast _gJToast;

        private void InitHier()
        {
            _inputField = transform.Find("InputField").GetComponent<TMP_InputField>();
            _startButton = transform.Find("_Button_Start").GetComponent<Button>();
            _startButton.onClick.AddListener(OnStartButtonClick);
            _gJToast = transform.Find("_GJToast#").GetComponentEx<GJToast>();

            _ruleButton = transform.Find("_Button_Rule").GetComponent<Button>();
            _ruleButton.onClick.AddListener(OnRuleButtonClick);
        }

        private void OnStartButtonClick()
        {
            Debug.LogWarning($"名字不能填空");
            if (_inputField.text.Equals(""))
            {
                Debug.LogWarning($"名字不能填空");

                _gJToast.Show("Please enter your name");
                return;
            }

            GameManager.Instance.playername = _inputField.text;

            _gJToast.Show("Please enter your name");

            UIManager.Instance.CloseView<GJStartLayer>();
            GJ25Layer.Create();
        }


        private void OnRuleButtonClick()
        {
            GJRuleLayer.Create();
        }
        // Hier Components End

        // Event Methods Begin
        // Event Methods End

        // Private Methods Begin
        // Private Methods End
    }
}
